package cn.lblbc.appassit.utils

import android.content.Context
import android.content.SharedPreferences
import android.os.Environment

class SharedPreferencesHelper(var context: Context) {

    private val sharedPreferences: SharedPreferences = 
        context.getSharedPreferences("app_settings", Context.MODE_PRIVATE)

    companion object {
        private const val KEY_EXPORT_DIRECTORY = "export_directory"
    }

    fun getExportDirectory(): String {
        return sharedPreferences.getString(KEY_EXPORT_DIRECTORY, 
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath) 
            ?: Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath
    }

    fun setExportDirectory(directory: String) {
        sharedPreferences.edit()
            .putString(KEY_EXPORT_DIRECTORY, directory)
            .apply()
    }

    fun clearExportDirectory() {
        sharedPreferences.edit()
            .remove(KEY_EXPORT_DIRECTORY)
            .apply()
    }
}